//第1处补充代码，引入必要的类

import java.util.Comparator;

class Point        
{
    public int x, y;  
    public Point(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
    public Point()
    {
        this(0, 0);
    }
    public String toString()               
    {
        return "("+this.x+","+this.y+")";
    }
    public boolean equals(Object obj)           
    {
        if (!(obj instanceof Point)) return false;
        Point p = (Point) obj;
        return this.x == p.x && this.y == p.y;
    }
}
abstract class Figure
{
    public Point point1;
    protected Figure(Point point1) {
        this.point1 = point1;
    }
    public boolean equals(Object obj)           
    {
        if(obj instanceof Point)
        {
            Point p = (Point) obj;
            return this.point1.equals(p);
        }
        if (!(obj instanceof Figure)) return false;
        Figure f = (Figure) obj;
        return this.point1.equals(f.point1);
    }
}
interface Area                       
{
    public abstract double area();
}
interface Perimeter                
{
    public abstract double perimeter();
}
abstract class ClosedFigure extends Figure
        implements Area,Perimeter{
    protected String shape;
    protected ClosedFigure(String shape, Point point1)
    {
        super(point1);
        this.shape = shape;
    }
    protected ClosedFigure() {
        this("", new Point());
    }
}
class Rectangle extends ClosedFigure implements Comparable<Rectangle>//第2处补充代码
{
    protected int length, width;    
    public Rectangle(Point point1, int length, int width)
    {
        super("矩形", point1) ;   //第3处补充代码：调用父类的一个构造方法 
        this.length = length;
        this.width = width;
    }
    public Rectangle(Rectangle rec)                                                                 
    {
        this(rec.point1, rec.length, rec.width);    //第4处补充代码：调用本类已声明的构造方法 
    }
    public String toString()  
    {
        return "("+super.toString()+",长度"+this.length+",宽度"+this.width+")";   //第5处补充代码：调用父类的 toString()    
    }
    public double perimeter()    //第6处补充代码：实现计算矩形周长方法 
    {
        return (width + length) * 2;
    }
    public double area()    //第7处补充代码：实现计算矩形面积方法     
    {
          return length * width;
    }
     public boolean equals(Object obj)    //第8处补充代码：实现比较对象相等方法。覆盖       
    {
        if (obj == this) return true;
        if(obj instanceof Rectangle){
            Rectangle rec = (Rectangle) obj;
            return rec.point1.equals(this.point1) && this.length == rec.length && this.width == rec.width;
        }
        return false;
    }
    public int compareTo(Rectangle rec)    //第9处补充代码：按面积比较对象大小       
    {
       return (int)(this.area() - rec.area());
    }
}
class AreaComparator implements Comparator<Rectangle>//第10处补充代码：实现面积比较器
{
    @Override
    public int compare(Rectangle o1, Rectangle o2) //第11处补充代码：实现面积比较方法
    {
        return o1.compareTo(o2);
    }
}
class PerimeterComparator implements Comparator<Rectangle>//第12处补充代码：实现周长比较器
{
    public int compare(Rectangle o1, Rectangle o2)//第13处补充代码：实现周长比较方法
    {
        return (int)(o1.perimeter() - o2.perimeter());
    }
}

public class Main {
    public static void main(String[] args) {
        Point pt1 = new Point(10,10);
        Rectangle rec1 = new Rectangle(pt1, 40, 20);
        Rectangle rec2 = new Rectangle(rec1);
        Rectangle rec3 = new Rectangle(new Point(10,20),10,80);

        System.out.println(rec1.equals(pt1));
        System.out.println(rec1.equals(rec2));
        System.out.println(rec1.equals(rec3));
        System.out.println(rec1.compareTo(rec3));

        AreaComparator ac = new AreaComparator();
        PerimeterComparator pc = new PerimeterComparator();
        System.out.println(ac.compare(rec1,rec3));
        System.out.println(pc.compare(rec1,rec3));
    }
}